package test.baojia.act.operation;

import com.alibaba.fastjson.JSONObject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;

import java.util.Properties;

/**
 * 录入框控件操作。
 */
public class InputOperation extends WriteOperation {

    public void run(JSONObject context, WebDriver driver, Properties resource, JSONObject parentContext) throws Exception{
        super.run(context , driver , resource, parentContext);
        final String value = (String) this.context.get(OPERATION.byValue.toString());
        final String globalProperty = (String) this.context.get(OPERATION.byGlobalProperty.toString());
        WebElement we = this.makeWebElement(true);
        we.click();
        try{
            this.newWebDriverWait(null).until(
                    ExpectedConditions.attributeToBe(we , "value" , "")
            );
        }catch (Exception e){
            we.clear();
        }
        //resource.put("projectCode","SalemanRIB22020DN0327");
        if(globalProperty!=null && !"".equals(globalProperty)){
            String globalValue = (String) resource.get(globalProperty);
            we.sendKeys(globalValue);
        }else {
            we.sendKeys(value);
        }

    }

}
